package com.weishaoying.rws.service;

import com.weishaoying.rws.annotation.DataSource;
import com.weishaoying.rws.dao.UserMapper;
import com.weishaoying.rws.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 读写分离使用这个
 *
 * @author WeiShaoying
 * @date 2018/5/5
 */
//@Service
public class UserServiceRws {

    @Autowired
    private UserMapper userMapper;

    @DataSource("read")
    public User queryUser(Long id) {
        System.out.println("----queryUser = [" + id + "]");
        return userMapper.queryById(id);
    }

    @DataSource("read")
    public List<User> queryAll() {
        System.out.println("----queryAll");
        return userMapper.queryAll();
    }

    @DataSource("write")
    public void saveUser(User user) {
        System.out.println("----SaveUser = [" + user + "]");
        userMapper.saveUser(user);
    }

    @DataSource("write")
    public void deleteUser(Long id) {
        System.out.println("----deleteUser = [" + id + "]");
        userMapper.deleteById(id);
    }

    @DataSource("write")
    public void updateUser(User user) {
        System.out.println("----updateUser = [" + user + "]");
        userMapper.updateUser(user);
    }
}
